package com.xci.platform.auth.api;

import com.xci.platform.annotation.Authorize;
import com.xci.platform.auth.entity.ParamEntity;
import com.xci.platform.auth.service.ParamService;
import com.xci.platform.controller.BaseController;
import com.xci.platform.core.BoolMessage;
import com.xci.platform.helper.StringHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Authorize
@RestController
@RequestMapping("/api/auth/param")
public class ParamApiController extends BaseController {
    /**
     * 参数服务
     */
    @Resource
    private ParamService paramService;

    @PostMapping("/insert")
    public BoolMessage insert(@RequestBody ParamEntity entity){
        return paramService.save(entity,true);
    }

    @PostMapping("/update")
    public BoolMessage update(@RequestBody ParamEntity entity) {
        return paramService.save(entity,false);
    }

    @PostMapping("/delete")
    public BoolMessage delete(@RequestParam String ids) {
        for (String id : StringHelper.splitToArray(ids)) {
            paramService.delete(id);
        }
        return BoolMessage.True;
    }

    @PostMapping("/query")
    public BoolMessage query(@RequestParam Map params) {
        return BoolMessage.success(paramService.queryPage(params));
    }

    /**
     * 获取单个参数详细信息
     *
     * @param id 参数主键
     */
    @PostMapping("/querybyid")
    public BoolMessage queryById(@RequestParam("id") String id) {
        return BoolMessage.success(paramService.queryById(id));
    }

    /**
     * 导出参数
     */
    @PostMapping("/export")
    public void export(@RequestParam Map params) {
        //ExcelUtil.exportWeb(response, paramService.queryList(params), ParamEntity.class, "系统参数");
    }
}
